var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
	inputs[i].onblur = inputBlur;
}

function inputBlur() {
	var name = this.name;
	var value = this.value;
	var tip = this.placeholder;
	var div = this.parentNode.nextElementSibling.firstChild;
	value = value.trim();
	if(value == null || value == '') {
		div.innerHTML = "输入框不能为空";
		div.className = 'error';
	} else {
		var reg = getReg(name);
		if(value.match(reg)) {
			div.innerHTML = "输入正确";
			div.className = 'success'
		} else {
           div.innerHTML=tip;
           div.className='error';
		}
	}
}

function getReg(name){
	var reg='';
	switch(name){
		case 'username':
		reg=/^[a-zA-Z]{4,12}$/;
		break;
		case 'pwd':
		reg=/^\w{6,20}$/;
	    break;
	    case'repwd':
	    reg=document.getElementsByTagName('input')[1].value;
	    reg=new getReg('^'+pwd+'$');
	    break;
	    case 'tel':
	    reg=/^1[34578]\d{9}$/;
	    break;
	    default:
	    break;
	}
	return reg;
}
